package day_2022_9_to_12.Day;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author haomin
 * @date 2022/09/03 23:15
 **/
public class Day1_4_Num6173_MaximumRows {
    public static void main(String[] args) {
        maximumRows(new int[][]{{0,1,0,1,0,1,0,0,1,0,0,0},{0,0,1,1,0,1,1,0,1,1,0,0}}, 6);
    }
    private static int max = Integer.MIN_VALUE;
    public static int maximumRows(int[][] mat, int cols) {
        dfs(mat, 0, new ArrayList<Integer>(), cols);
        return max;
    }
    private static void dfs(int[][] mat, int index, List<Integer> list, int cols) {
        if(list.size() == cols){
            int[][] temp = copyArr(mat);
            int len = 0;
            while(len < list.size()){
                setZero(temp, list.get(len));
                len++;
            }
            System.out.println(judgeRow(temp));
            for (int[] ints : temp) {
                System.out.println(Arrays.toString(ints));
            }
            max = Math.max(max, judgeRow(temp));
            return;
        }
        for(int i = index; i < mat[0].length; ++i){
            list.add(i);
            dfs(mat,i+1, list, cols);
            list.remove(list.size()-1);
        }
    }

    private static int[][] copyArr(int[][] mat) {
        int[][] arr = new int[mat.length][mat[0].length];
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[0].length; j++) {
                arr[i][j] = mat[i][j];
            }
        }
        return arr;
    }

    private static void setZero(int[][] mat, int col){
        for(int i = 0; i < mat.length; ++i){
            mat[i][col] = 0;
        }
    }
    private static int judgeRow(int[][] mat){
        int count = 0;
        for(int i = 0; i < mat.length; ++i){
            int flag = 1;
            for(int j = 0; j < mat[0].length-1; ++j){
                if(mat[i][j] != mat[i][j+1]) flag = 0;
            }
            count += flag;
        }
        return count;
    }
}